package cn.virens.web.controller.manage.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.virens.common.RequestUtil;
import cn.virens.components.page.PageParamUser;
import cn.virens.components.page.PageResult;
import cn.virens.database.mysql.model.sys.SysResource;
import cn.virens.service.inter.sys.SysResourceService;
import cn.virens.web.common.BaseTableController;

/**
 * 资源管理 - sys_resource
 *
 * @author Virens
 * @since  2018-08-25 15:40:43
 */
@Controller
@RequestMapping("/manage/sys/resource")
public class SysResourceContorller extends BaseTableController<SysResource, SysResourceService> {

	public SysResourceContorller() {
		super("/manage/sys/resource", "sys:resource");
		super.disable(API_CREATE, API_DELETE);
	}

	@RequestMapping("update.jspx")
	public String updateJspx(@RequestParam("id") String id, HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAttribute("rootList", mBaseService.selectRoot());
		model.addAttribute("record", mBaseService.selectOne(id));

		return returnUrl("update");
	}

	@Override
	protected PageResult<?> listHandle(HttpServletRequest request, PageParamUser page) throws Exception {
		page.addParam("name", RequestUtil.getValueStr(request, "name", null));
		page.addParam("pid", RequestUtil.getValueInt(request, "pid", null));
		page.addParam("id", RequestUtil.getValueInt(request, "id", null));

		return super.listHandle(request, page);
	}
}
